using System.Linq;

namespace LongestCommonPrefix
{
    public class Solution
    {
        public string LongestCommonPrefix(string[] strs)
        {
            if (strs.Length == 0)
            {
                return "";
            }

            if (strs.Length == 1)
            {
                return strs[0];
            }

            var i = 0;
            for (i = 0; i < strs[0].Length; i++)
            {
                var j = 0;
                for (j = 1; j < strs.Length; j++)
                {
                    if (strs[j].Length <= i || strs[0][i] != strs[j][i])
                    {
                        break;
                    }
                }

                if (j < strs.Length)
                {
                    break;
                }
            }

            return strs[0].Substring(0, i);
        }
    }
}